<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">停下</button>
    <!-- 每隔多久就定时一下 -->
    <!-- 启动一个定时器(setInterval)，点击停下按钮后，清除定时器 -->
    <script>
        const btn = document.querySelector('#btn');
        btn.addEventListener('click', () => {
            clearInterval(interval);
        });
        var i = 1;
        let b = 2;
        // 作用域链查找   定时器的id
        var interval = setInterval(() => {
            // clearInterval(interval);
            // 箭头函数 简版的函数 
            // console.log(i++);
            console.log(this.i++); //this->window
            console.log(this.b++); //NaN
            console.log(this.b); //undefined

        }, 1000)
    </script>
</body>

</html>